package com.ewing.common.filter;

import java.io.IOException;

import javax.annotation.Resource;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.ewing.busi.stat.dao.StatAccessLogDao;
import com.ewing.common.constants.FrontParamConstants;
import com.ewing.common.utils.BasePraramUtils;
import com.ewing.utils.CodecUtils;
import com.ewing.utils.IntegerUtils;

public class InitFilter implements Filter {

    /**
     * 默认生成的该类的LOG记录器，使用slf4j组件。避免产生编译警告，使用protected修饰符。
     */
    protected final static Logger LOG = LoggerFactory.getLogger(InitFilter.class);

    @Resource
    private StatAccessLogDao statAccessLogDao;

    @Override
    public void destroy() {
    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse resp = (HttpServletResponse) response;

        Integer shopId = IntegerUtils.parseInt(BasePraramUtils.getShopId());
        if (!IntegerUtils.nullOrZero(shopId)) {
            Integer smallShopId = CodecUtils.smallInt(shopId);
            req.setAttribute(FrontParamConstants.SHOP_ID, smallShopId);
        }
        
        chain.doFilter(req, resp);
    }

    @Override
    public void init(FilterConfig arg0) throws ServletException {
        // TODO Auto-generated method stub

    }
}
